package com.du.web; /**
 * @author : DuJiabao
 * @Date : 2021/1/28 22:23
 * @Project : bookstore
 * @File : ${FILE_NAME}
 * @Desc :
 */

import com.du.pojo.User;
import com.du.service.UserService;
import com.du.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "LoginServlet", value = "/loginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserService userService = new UserServiceImpl();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        if (userService.loginUser(user) != null) {
            System.out.println("登录成功！");
            request.getRequestDispatcher("pages/user/login_success.html").forward(request, response);
            return;
        }
        System.out.println("登录失败");
        request.getRequestDispatcher("pages/user/login.html").forward(request, response);

    }
}
